#pragma once
#include"Protocol.hpp"
#include<iostream>
#include"TcpServer.hpp"
#include"task.hpp"
#include"Treadpool.hpp"
#include"log.hpp"
#define PORT 8080

class Httpserver{

private:
    int _port;
    TcpServer*tcp_svr;
    bool stop;



public:
    Httpserver(int port=PORT)
    :_port(port),tcp_svr(nullptr),stop(false)
    {

    }

    void InitServer(){
        tcp_svr=TcpServer::getinstance(_port);
    }

    void Loop(){
        LOG(INFO,"Loop begin");
        int listenfd=tcp_svr->Sock();
        while(!stop){
            //todo
            int newfd=tcp_svr->Accept();

            Task task(newfd);
            ThreadPool::GetInstand()->PushTask(task);

            // int *_sock=new int(newfd);
            // pthread_t tid;
            // pthread_create(&tid,nullptr,Entrance::HandlerRequset,_sock);
            // cout<<"已经尝试创建线程"<<endl;
            // pthread_detach(tid);
        }
    } 

    ~Httpserver()
    {

    }

};